#include<reg51.h>

#define NODE1_ADDR 1
#define NODE2_ADDR 2

unsigned char str[] = {"0123456789ABCDEF"};

unsigned char num[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xd8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void display_2(unsigned ch) 
{
    if((ch>=48)&&(ch<=57)) 
        P2=num[ch-48];
    else if((ch>=65)&&(ch<=70)) 
        P2=num[ch-55];
}

void display_1(unsigned ch) 
{
    if((ch>=48)&&(ch<=57)) 
        P0=num[ch-48];
    else if((ch>=65)&&(ch<=70)) 
        P0=num[ch-55];
}


void main()
{
    TH1 = TL1 = 0xfd;
    TMOD = 0x20;
    SCON = 0xf0;
    TR1 = 1;
    ES = 1;
    EA = 1;
    while(1);
}

void delay(unsigned int time)
{
    unsigned char i, j;
    for (i = 0; i < 130; i++)
    {
        for (j = 0; i < time; j++);
    }
}

void receive() interrupt 4
{
    RI = 0;
    if (RB8 == 1)
    {
        if (SBUF == NODE1_ADDR)
        {
            SM2 = 0;
            display_1(SBUF);
        }else if (SBUF == NODE2_ADDR)
        {
            SM2 = 0;
            display_2(SBUF);
        }
    }
    SM2 = 1;
}
